home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / point_3d.cp < prev    next >
Encoding:
Text File  |  1995-03-25  |  6.2 KB  |  112 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    point_3d.cp
  3. //    Date:                    8/26/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the methods for a point_3d
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "point_3d.h"
  11. #include "vector_3d.h"
  12.  
  13. //------------------------------------------------------------------------------
  14. //    global variables
  15. //------------------------------------------------------------------------------
  16. point_3d    ORIGIN_3D (R(0.0), R(0.0), R(0.0));                                                                        //    the origin of the coordinate system
  17.  
  18. //------------------------------------------------------------------------------
  19. //    constructor
  20. //------------------------------------------------------------------------------
  21. point_3d::point_3d (real x, real y, real z, real w) : tuple_3d (x, y, z, w)            //    constructor from three values
  22. {                                                                                                                                                                //    begin
  23.     if (w != R(1.0))                                                                                                                            //    if the homogenous coordinate is not a valid projection
  24.     {                                                                                                                                                            //    begin
  25.         xyz[X] /= w; xyz[Y] /= w; xyz[Z] /= w; xyz[W] = R(1.0);                                            //    divide the coordinates by w
  26.     }                                                                                                                                                            //    end
  27. }                                                                                                                                                                //    end
  28.  
  29. //------------------------------------------------------------------------------
  30. //    constructor
  31. //------------------------------------------------------------------------------
  32. point_3d::point_3d (const point_3d &p) : tuple_3d (p)                                                        //    copy constructor
  33. {                                                                                                                                                                //    begin
  34. }                                                                                                                                                                //    end
  35.  
  36. //------------------------------------------------------------------------------
  37. //    constructor
  38. //------------------------------------------------------------------------------
  39. point_3d::point_3d (const vector_3d &v) : tuple_3d (v[X], v[Y], v[Z], 1)                //    constructor from a vector_3d
  40. {                                                                                                                                                                //    begin
  41. }                                                                                                                                                                //    end
  42.  
  43. //------------------------------------------------------------------------------
  44. //    constructor
  45. //------------------------------------------------------------------------------
  46. point_3d::point_3d (const tuple_3d &t)                                                                                    //    constructor from a tuple_3d
  47. {                                                                                                                                                                //    begin
  48.     real    w = t[W];                                                                                                                                //    get the homogenous coordinate
  49.     if (w != R(1.0))                                                                                                                            //    if the homogenous ccordinate needs to be divided
  50.     {                                                                                                                                                            //    begin
  51.         xyz[X] = t[X] / w; xyz[Y] = t[Y] / w;                                                                                //    copy the values into the tuple_3d
  52.         xyz[Z] = t[Z] / w; xyz[W] = R(1.0);                                                                                    //    copy the values into the tuple_3d
  53.     }                                                                                                                                                            //    end
  54.     else                                                                                                                                                    //    otherwise
  55.     {                                                                                                                                                            //    begin
  56.         xyz[X] = t[X]; xyz[Y] = t[Y];                                                                                                //    copy the values into the tuple_3d
  57.         xyz[Z] = t[Z]; xyz[W] = t[W];                                                                                                //    copy the values into the tuple_3d
  58.     }                                                                                                                                                            //    end
  59. }                                                                                                                                                                //    end
  60.  
  61. //------------------------------------------------------------------------------
  62. //    assignment
  63. //------------------------------------------------------------------------------
  64. point_3d    &point_3d::operator = (const point_3d &p)                                                            //    assignment operator
  65. {                                                                                                                                                                //    begin
  66.     tuple_3d::operator () (p[X], p[Y], p[Z], p[W]);                                                                //    copy the values
  67.     return *this;                                                                                                                                    //    return the reference to this
  68. }                                                                                                                                                                //    end
  69.  
  70. //------------------------------------------------------------------------------
  71. //    assignment
  72. //------------------------------------------------------------------------------
  73. point_3d    &point_3d::operator = (const tuple_3d &t)                                                            //    assignment operator
  74. {                                                                                                                                                                //    begin
  75.     real    w = t[W];                                                                                                                                //    get the homogenous coordinate
  76.     if (w != R(1.0))                                                                                                                            //    if the homogenous ccordinate needs to be divided
  77.         tuple_3d::operator () (t[X] / w, t[Y] / w, t[Z] / w, R(1.0));                                //    copy the values, dividing by the homogenous coordinate
  78.     else                                                                                                                                                    //    otherwise
  79.         tuple_3d::operator = (t);                                                                                                        //    copy the values
  80.     return *this;                                                                                                                                    //    return the reference to this
  81. }                                                                                                                                                                //    end
  82.  
  83. //------------------------------------------------------------------------------
  84. //    assignment by values
  85. //------------------------------------------------------------------------------
  86. void    point_3d::operator () (real x, real y, real z, real w)                                        //    function call operator
  87. {                                                                                                                                                                //    begin
  88.     tuple_3d::operator () (x, y, z, w);                                                                                        //    assign the values
  89. }                                                                                                                                                                //    end
  90.  
  91. //------------------------------------------------------------------------------
  92. //    subtraction
  93. //------------------------------------------------------------------------------
  94. vector_3d    point_3d::operator - (const point_3d &p) const                                                //    subtraction operator
  95. {                                                                                                                                                                //    begin
  96.     return vector_3d (    xyz[X] - p[X],                                                                                         //    return a vector_3d, x subtraction
  97.                                     xyz[Y] - p[Y],                                                                                                 //    y subtraction
  98.                                     xyz[Z] - p[Z]);                                                                                                //    z subtraction
  99. }                                                                                                                                                                //    end
  100.  
  101. //------------------------------------------------------------------------------
  102. //    addition of a vector_3d
  103. //------------------------------------------------------------------------------
  104. point_3d    point_3d::operator + (const vector_3d &v) const                                                //    addition of a vector_3d to a point_3d
  105. {                                                                                                                                                                //    begin
  106.     return point_3d (xyz[X] + v[X],                                                                                             //    return a point_3d, x addition
  107.                                 xyz[Y] + v[Y],                                                                                                     //    y addition
  108.                                 xyz[Z] + v[Z]);                                                                                                    //    z addition
  109. }                                                                                                                                                                //    end
  110.  
  111. //------------------------------------------------------------------------------
  112.